package edu.java.texbooks.scjp.threads.test04.mailbox.rough;

import java.util.Scanner;

public class Publisher extends Thread {

	// --- Instance Variables ----------------------------------------
	private Mailbox myMailbox = null;
	private static final int TIME_INTERVAL = 50;

	// --- Constructors ----------------------------------------------
	public Publisher(Mailbox mailbox) {
		myMailbox = mailbox;
	}

	// --- Methods ---------------------------------------------------
	@Override
	public void run() {
		while (true) {
			if (myMailbox.request == false) {
				System.out.println("Publisher asks you to enter message: ");
				Scanner input= new Scanner(System.in);
				myMailbox.message= input.nextLine();
				myMailbox.request=true;
			}
			
			try {
				Thread.sleep(TIME_INTERVAL);
			} catch (InterruptedException ie) {
				System.out.println("Publisher thread interruted");
			}
		}
	}

}
